﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using CSP.Model.CSP;
using System.ComponentModel.DataAnnotations;

namespace CSP.DataAccess.Mapping
{
    public class ServiceImageMap : EntityTypeConfiguration<ServiceImage>
    {
        public ServiceImageMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            /*Modified by hanlei at 2012-9-8 start*/
            // Properties
            this.Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            /*Modified by hanlei at 2012-9-8* end*/


            this.Property(t => t.Name)
                .HasMaxLength(100);

            this.Property(t => t.FilePath)
                .IsRequired()
                .HasMaxLength(200);

            this.Property(t => t.FileName)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.OrderId);

            // Table & Column Mappings
            this.ToTable("ServiceImage");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ServiceInfoId).HasColumnName("ServiceInfoId");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.FilePath).HasColumnName("FilePath");
            this.Property(t => t.FileName).HasColumnName("FileName");
            this.Property(t => t.OrderId).HasColumnName("OrderId");

            // Relationships
            this.HasRequired(t => t.ServiceInfo)
                .WithMany(t => t.ServiceImages)
                .HasForeignKey(d => d.ServiceInfoId).WillCascadeOnDelete(true);

            /*Added by hanlei at 2012-9-8 start*/
            //不进行数据库适配
            Ignore(t => t.ImageOperateSatus);
            /*Added by hanlei at 2012-9-8 end*/
        }

    }
}
